﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace LimpaGaragem.DAO.Product
{
    public class ScoreRate
    {
        /// <summary>
        /// Return list of score rate
        /// </summary>
        /// <returns></returns>
        public List<LimpaGaragem.Model.Product.ScoreRate> GetListOfScoreRate()
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR015_ListProductScoreRates", 0);

                List<LimpaGaragem.Model.Product.ScoreRate> objListOfScoreRate = new List<LimpaGaragem.Model.Product.ScoreRate>();
                foreach (DataRow objDataRow in objDataTable.Rows)
                {
                    LimpaGaragem.Model.Product.ScoreRate objScoreRate = new LimpaGaragem.Model.Product.ScoreRate();
                    objScoreRate.ID = Convert.ToInt32(objDataRow["ID_RATE_SCORE"]);
                    objScoreRate.Name = objDataRow["NM_RATE_SCORE"].ToString();
                    objScoreRate.Score = Convert.ToDecimal(objDataRow["NU_SCORE"]);
                    objListOfScoreRate.Add(objScoreRate);
                }
                return objListOfScoreRate;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Return data of score rate
        /// </summary>
        /// <returns></returns>
        public LimpaGaragem.Model.Product.ScoreRate GetScoreRate(int IDScoreRate)
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();

                //PARAMETERS
                List<SqlParameter> objListOfParameters = new List<SqlParameter>();
                objListOfParameters.Add(new SqlParameter("@ID_RATE_SCORE", IDScoreRate));

                //RETURN DATA
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR015_SelectScoreRate", 0, objListOfParameters);

                LimpaGaragem.Model.Product.ScoreRate objScoreRate = null;
                if (objDataTable.Rows.Count > 0)
                {
                    objScoreRate = new LimpaGaragem.Model.Product.ScoreRate();
                    objScoreRate.ID = IDScoreRate;
                    objScoreRate.Name = objDataTable.Rows[0]["NM_RATE_SCORE"].ToString();
                    objScoreRate.Score = Convert.ToDecimal(objDataTable.Rows[0]["NU_SCORE"]);
                }
                return objScoreRate;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
